package imachine.test.groupcall;

import imachine.*;

public class GroupCallMachine extends Machine {
	public static final int ID = 10;
	public static final String name = "GrpCallFSM";

	public static final int DISAFFILIATED_STATE = 0;
	public static final int AFFILIATING_STATE = 1;
	public static final int AFFILIATED_STATE = 2;
	public static final int CONNECTING_STATE = 3;
	public static final int CONNECTED_STATE = 4;
	public static final int DISCONNECTING_STATE = 5;
	public static final int STATE_NUM = 6;
	
	public static final int DISAFFILIATED_TO_AFFILIATING_TRAN = 0;
	public static final int AFFILIATING_TO_AFFILIATED_TRAN = 1;
	public static final int AFFILIATED_TO_CONNECTING_TRAN = 2;
	public static final int CONNECTING_TO_CONNECTED_TRAN = 3;
	public static final int CONNECTED_TO_DISCONNECTING_TRAN = 4;
	public static final int DISCONNECTING_TO_AFFILIATED_TRAN = 5;
	public static final int TRANSITION_NUM = 6;

	public static final int AFFILIATE_EVENT = 0;
	public static final int AFFILIATED_EVENT = 1;
	public static final int INVITE_EVENT = 2;
	public static final int INVITE_ACCEPTED_EVENT = 3;
	public static final int DISCONNECT_EVENT = 4;
	public static final int DISCONNECTED_EVENT = 5;
	
	public static final int ENTRY_STATE = DISAFFILIATED_STATE;

	private GroupCallMachine() {
		super();
		
		states.add(new State(DISAFFILIATED_STATE));
		states.add(new State(AFFILIATING_STATE));
		states.add(new State(AFFILIATED_STATE));
		states.add(new State(CONNECTING_STATE));
		states.add(new State(CONNECTED_STATE, 
				ConnectedMachine.getInstance()));
		states.add(new State(DISCONNECTING_STATE));

		transitions.add(new Transition(DISAFFILIATED_TO_AFFILIATING_TRAN,
				DISAFFILIATED_STATE,
				AFFILIATING_STATE));
		transitions.add(new Transition(AFFILIATING_TO_AFFILIATED_TRAN,
				AFFILIATING_STATE,
				AFFILIATED_STATE));
		transitions.add(new Transition(AFFILIATED_TO_CONNECTING_TRAN,
				AFFILIATED_STATE,
				CONNECTING_STATE));
		transitions.add(new Transition(CONNECTING_TO_CONNECTED_TRAN,
				CONNECTING_STATE,
				CONNECTED_STATE));
		transitions.add(new Transition(CONNECTED_TO_DISCONNECTING_TRAN,
				CONNECTED_STATE,
				DISCONNECTING_STATE));
		transitions.add(new Transition(DISCONNECTING_TO_AFFILIATED_TRAN,
				DISCONNECTING_STATE,
				AFFILIATED_STATE));
		
		triggers.add(new Trigger(AFFILIATE_EVENT, 
				DISAFFILIATED_TO_AFFILIATING_TRAN));
		triggers.add(new Trigger(AFFILIATED_EVENT, 
				AFFILIATING_TO_AFFILIATED_TRAN));
		triggers.add(new Trigger(INVITE_EVENT, 
				AFFILIATED_TO_CONNECTING_TRAN));
		triggers.add(new Trigger(INVITE_ACCEPTED_EVENT, 
				CONNECTING_TO_CONNECTED_TRAN));
		triggers.add(new Trigger(DISCONNECT_EVENT, 
				CONNECTED_TO_DISCONNECTING_TRAN));
		triggers.add(new Trigger(DISCONNECTED_EVENT, 
				DISCONNECTING_TO_AFFILIATED_TRAN));
	}
	
	public static GroupCallMachine getInstance() {
		if (instance == null) {
			instance = new GroupCallMachine();
		}
		return instance;
	}

	public String getName() {
		return name;
	}

	public int getId() {
		return ID;
	}

	public int getEntryStateId() {
		return ENTRY_STATE;
	}
	

	private static GroupCallMachine instance = null;
}
